<?php
/**
 * 地图皮肤
 */
namespace App;

use Model\MapSkinMod;

class MapSkin extends Action
{
    private $MapSkin = null;

    private $_system_skin = array(
        array("name"=>"默认","value"=>"normal"),
        array("name"=>"幻影黑","value"=>"dark"),
        array("name"=>"月光银","value"=>"light"),
        array("name"=>"远山黛","value"=>"whitesmoke"),
        array("name"=>"草色青","value"=>"fresh"),
        array("name"=>"雅士灰","value"=>"grey"),
        array("name"=>"涂鸦","value"=>"graffiti"),
        array("name"=>"马卡龙","value"=>"macaron"),
        array("name"=>"靛青蓝","value"=>"blue"),
        array("name"=>"极夜蓝","value"=>"darkblue"),
        array("name"=>"酱籽","value"=>"wine")
    );
	public function __construct()
	{
		parent::__construct();
		$this->MapSkin = new MapSkinMod();
	}

    /**
     * 添加皮肤
     */
	public function add()
    {
        $this->_gpc["data"]["uniacid"] = $this->_uniacid;
        if($this->MapSkin->insert($this->_gpc["data"])){
            $this->_result = array("status"=>"success");
        }
        $this->result($this->_result);
    }

    /**
     * 创建系统皮肤
     */
	public function createSystemSkin()
    {
        $_skin = $this->MapSkin->findOne(array("uniacid"=>$this->_uniacid,"source"=>2),array("id"));
        if(!$_skin){
            $_data = array("uniacid"=>$this->_uniacid,"source"=>2);
            foreach($this->_system_skin as $_v){
                $_data["name"] = $_v["name"];
                $_data["value"] = $_v["value"];
                $this->MapSkin->insert($_data);
            }
            $this->_result = array("status"=>"success");
        }
        $this->result($this->_result);
    }

    /**
     * 获取皮肤列表
     */
    public function getSkinList()
    {
        $_list = $this->MapSkin->findAll(array("uniacid"=>$this->_uniacid),array("order"=>array("id","asc"),"limit"=>$this->_gpc["limit"]),array("id","name","value","source"));
        $this->_result = array("status"=>"success","data"=>$_list);
        $this->result($this->_result);
    }

    /**
     * 获取皮肤总数
     */
    public function getSkinTotal()
    {
        $this->_result = array("status"=>"success","data"=>$this->MapSkin->total(array("uniacid"=>$this->_uniacid)));
        $this->result($this->_result);
    }

    /**
     * 删除皮肤
     */
    public function delete()
    {
        if($this->MapSkin->delete(array("id"=>$this->_gpc["skin_id"]))){
            $this->_result = array("status"=>"success");
        }
        $this->result($this->_result);
    }
}